#!/bin/sh 
# 
# $BASENAME - this script starts and stops the $PROG_NAME daemin 
# 
# chkconfig: 345 85 15
# description: php-fpm is userd for LNMP
# processname: $BASENAME
# config: $CONF_FILE
# pidfile: $PID_FILE

# Source function library. 
. /etc/rc.d/init.d/functions 

# Source networking configuration. 
. /etc/sysconfig/network 

# Check that networking is up. 
[ "$NETWORKING" = "no" ] && exit 1
 
PREFIX="/usr/local/php"
EXEC_PROG="$PREFIX/sbin/php-fpm" 
CONF_FILE="$PREFIX/etc/php-fpm.conf" 
PID_FILE="$PREFIX/var/run/php-fpm.pid"
BASENAME=$(basename $EXEC_PROG)
PROG_NAME=$BASENAME

start() { 
[ -x $EXEC_PROG ] || exit 5 
[ -f $CONF_FILE ] || exit 6
echo -n $"Starting $PROG_NAME ..." 
daemon $EXEC_PROG -y $CONF_FILE -g $PID_FILE -D 
retval=$? 
echo 
[ $retval -eq 0 ] && touch $PID_FILE 
return $retval
} 

stop() { 
echo -n $"Stopping $PROG_NAME ..." 
killproc -p $PID_FILE $BASENAME -QUIT 
retval=$? 
echo
return $retval 
} 

restart() { 
configtest || return $? 
stop 
start 
} 

force_reload() { 
restart 
} 

configtest() { 
$EXEC_PROG -t -c $CONF_FILE >/dev/null 2>&1
#[ "$?" != "0" ] && exit 1
} 

rh_status() { 
status -p $PID_FILE $BASENAME
} 

rh_status_q() { 
rh_status >/dev/null 2>&1 
} 

case "$1" in 
	start) 
		rh_status_q && exit 0 
		$1
	;;
	stop) 
		rh_status_q || exit 0 
		$1 
	;;
	restart|configtest|force-reload) 
		$1 
	;;
	reload) 
		restart 
	;;
	status) 
		rh_status 
	;;
	condrestart|try-restart) 
		rh_status_q || exit 0 
	;;
	*) 
	echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload|configtest}" 
	exit 2 
esac
